<?php
/**
 *
 *个人档案
 * 
 */
namespace Admin\Controller;
use Think\Comtroller;
use Common\Controller\BaseController;

class DocumentController extends BaseController {

	//获取档案信息
	public function Index() {
		$res = array('rcode'=>0,'data'=>NULL, 'msg'=> 'OK');
		$UExt = D('Employee','Model', 'Admin');
		$uid = I('get.user_id',0,'intval');
		// dump($uid);
		$contentList = $UExt->common($uid);
		$contentList['postExch'] = $UExt->getHrPosById($uid); //岗位异动
		$contentList['trainCom'] = $UExt->getHrTraComById($uid); //入司培训
		$contentList['commend'] = $UExt->getHrCommById($uid); //嘉奖记录
		$contentList['punish'] = $UExt->getChufaById($uid); //处罚记录
		$contentList['offer'] = $UExt->getHrOffById($uid); //特殊贡献
		if($contentList){
			$res['rcode'] = 1;
			$res['data'] = $contentList;
		}else{
			$res['msg'] == '获取信息失败';
		}
		e_json( $res );
	}

	//编辑时原始信息
	public function getEditInfo() {
		$res = array('rcode'=>0,'data'=>NULL, 'msg'=> 'OK');
		$UExt = D('Employee','Model', 'Admin');
		$uid = I('get.user_id',0,'intval');
		$contentList = $UExt->common($uid);
		$contentList['family'] = $UExt->getHrFamById($uid); //家庭成员
		$contentList['education'] = $UExt->getHrEduById($uid); //教育经历
		$contentList['train'] = $UExt->getHrTraById($uid); //培训经历
		$contentList['workexp'] = $UExt->getGongzuoById($uid); //工作经历
		if($contentList){
			$res['rcode'] = 1;
			$res['data'] = $contentList;
		}else{
			$res['msg'] == '获取信息失败';
		}
		e_json( $res );
	}

	//保存信息
	public function editEmpl() {
		$res = array('data'=>NULL,'msg'=>'','rcode'=>0);
		$UExt = D('Employee','Model', 'Admin');
		$userData = $_POST['user'];
		$emplData = $_POST['empl'];
		$famlyData = $_POST['family'];
		$eduData = $_POST['edu'];
		$trainData = $_POST['train'];
		$workData = $_POST['work'];
		$UExt->startTrans();
		// dump($userData['user_id']);
		$emplData['ext_sh_status'] = 1;
		$ueRes = $UExt->saveDecInfo($userData['user_id'],$userData,$emplData);
		// $userRes = M('user')->where('user_id='.$userData['user_id'])->save($userData);
		// $res = M('user_extension')->where('user_id='.$userData['user_id'])->find();
		// $emplRes = '';
		// if( $res ) {
		// 	$emplRes = M('user_extension')->where('user_id='.$userData['user_id'])->save($emplData);
		// }else{
		// 	$emplData['user_id'] = $userData['user_id'];
		// 	$emplRes = M('user_extension')->add($emplData);
		// }
		
		
		$famRes = $UExt->editFamily($userData['user_id'],$famlyData);
		$eduRes = $UExt->editEdu($userData['user_id'],$eduData);
		$trainRes = $UExt->editTrain($userData['user_id'],$trainData);
		$workRes = $UExt->editWorkExp($userData['user_id'],$workData);
		// dump($userRes);
		if($ueRes['r'] &&  is_numeric($famRes) &&  is_numeric($eduRes) &&  is_numeric($trainRes) &&  is_numeric($workRes)){
			$UExt->commit();
			$res['rcode'] = 1;
			$res['msg'] = '信息编辑成功';
			$res['data'] = $workRes;	
		}else{
			$UExt->rollback();
			$res['msg'] = "信息编辑失败";
			$res['data'] = $workRes;
		}
		e_json($res);
	}

}